package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsLineBodyOutboundMapper;
import me.zhengjie.pojo.entity.WcsLineBodyOutbound;
import me.zhengjie.sqlservice.WcsLineBodyOutboundService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class WcsLineBodyOutboundServiceImpl extends ServiceImpl<WcsLineBodyOutboundMapper, WcsLineBodyOutbound> implements WcsLineBodyOutboundService {
    private final WcsLineBodyOutboundMapper wcsLineBodyOutboundMapper;

    @Override
    public WcsLineBodyOutbound selectOne() {
        return wcsLineBodyOutboundMapper.selectOne(null);
    }

    @Override
    public boolean updateOneWritePlc(Integer id, int oneWritePlc) {
        LambdaUpdateWrapper<WcsLineBodyOutbound> wcsLineBodyOutboundLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyOutboundLambdaUpdateWrapper.set(WcsLineBodyOutbound::getOneWritePlc,oneWritePlc)
                .eq(WcsLineBodyOutbound::getId,id);
        return wcsLineBodyOutboundMapper.update(null,wcsLineBodyOutboundLambdaUpdateWrapper) >0;
    }

    @Override
    public boolean updateReadCodeWritePlc(Integer id, int readCodeWritePlc) {
        LambdaUpdateWrapper<WcsLineBodyOutbound> wcsLineBodyOutboundLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyOutboundLambdaUpdateWrapper.set(WcsLineBodyOutbound::getReadCodeWritePlc,readCodeWritePlc)
                .set(WcsLineBodyOutbound::getReadTimi, LocalDateTime.now())
                .eq(WcsLineBodyOutbound::getId,id);
        return wcsLineBodyOutboundMapper.update(null,wcsLineBodyOutboundLambdaUpdateWrapper) >0;
    }

    @Override
    public boolean updateOneAgvTransportPlc(Integer id, int oneAgvTransportPlc) {
        LambdaUpdateWrapper<WcsLineBodyOutbound> wcsLineBodyOutboundLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyOutboundLambdaUpdateWrapper.set(WcsLineBodyOutbound::getOneAgvTransportPlc,oneAgvTransportPlc)
                .eq(WcsLineBodyOutbound::getId,id);
        return wcsLineBodyOutboundMapper.update(null,wcsLineBodyOutboundLambdaUpdateWrapper) >0;
    }

    @Override
    public boolean updateTwoAgvTransportPlc(Integer id, int twoAgvTransportPlc) {
        LambdaUpdateWrapper<WcsLineBodyOutbound> wcsLineBodyOutboundLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyOutboundLambdaUpdateWrapper.set(WcsLineBodyOutbound::getTwoAgvTransportPlc,twoAgvTransportPlc)
                .eq(WcsLineBodyOutbound::getId,id);
        return wcsLineBodyOutboundMapper.update(null,wcsLineBodyOutboundLambdaUpdateWrapper) >0;
    }
}
